package com.fr.report.semantic;

import com.fr.base.ColumnRow;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.TableData;
import com.fr.data.condition.Condition;
import com.fr.data.condition.LiteConditionUtils;
import com.fr.data.core.DataXMLUtils;
import com.fr.report.ReportParameterAttr;
import com.fr.report.ReportSettings;
import com.fr.report.TemplateReport;
import com.fr.report.TemplateWorkBook;
import com.fr.report.WorkBook;
import com.fr.report.WorkSheet;
import com.fr.report.parameter.Parameter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class AbstractWizardRpt
  implements WizardRpt
{
  private List tableDataNameList = new ArrayList();
  private List tableDataList = new ArrayList();
  private boolean showParameterWindow = true;
  private int parameterWindowPosition = 1;

  public void setShowParameterWindow(boolean paramBoolean)
  {
    this.showParameterWindow = paramBoolean;
  }

  public boolean isShowParameterWindow()
  {
    return this.showParameterWindow;
  }

  public int getParameterWindowPosition()
  {
    return this.parameterWindowPosition;
  }

  public void setParameterWindowPosition(int paramInt)
  {
    this.parameterWindowPosition = paramInt;
  }

  public WorkBook generateWorkBook()
  {
    WorkBook localWorkBook = new WorkBook();
    WorkSheet localWorkSheet = new WorkSheet();
    localWorkBook.addReport(localWorkSheet);
    localWorkSheet.getReportSettings().setShrinkToFitMode(1);
    Iterator localIterator = getTableDataNameIterator();
    while (localIterator.hasNext())
    {
      localObject = (String)localIterator.next();
      TableData localTableData = getTableData((String)localObject);
      localWorkBook.putTableData((String)localObject, localTableData);
    }
    insertIntoReport(localWorkSheet, ColumnRow.valueOf(0, 0));
    Object localObject = localWorkBook.getReportParameterAttr();
    if (localObject == null)
    {
      localObject = new ReportParameterAttr();
      localWorkBook.setReportParameterAttr((ReportParameterAttr)localObject);
    }
    ((ReportParameterAttr)localObject).setShowWindow(isShowParameterWindow());
    ((ReportParameterAttr)localObject).setWindowPosition(getParameterWindowPosition());
    return ((WorkBook)localWorkBook);
  }

  public abstract void insertIntoReport(TemplateReport paramTemplateReport, ColumnRow paramColumnRow);

  public Iterator getTableDataNameIterator()
  {
    return this.tableDataNameList.iterator();
  }

  public TableData getTableData(String paramString)
  {
    int i = this.tableDataNameList.indexOf(paramString);
    if (i == -1)
      return null;
    return ((TableData)this.tableDataList.get(i));
  }

  public void putTableData(String paramString, TableData paramTableData)
  {
    if (paramString == null)
      return;
    int i = this.tableDataNameList.indexOf(paramString);
    if (paramTableData == null)
    {
      if (i != -1)
      {
        this.tableDataNameList.remove(i);
        this.tableDataList.remove(i);
      }
    }
    else if (i != -1)
    {
      this.tableDataList.set(i, paramTableData);
    }
    else
    {
      this.tableDataNameList.add(paramString);
      this.tableDataList.add(paramTableData);
    }
  }

  public boolean renameTableData(String paramString1, String paramString2)
  {
    if ((paramString2 == null) || (paramString1 == null))
      return false;
    if (ComparatorUtils.equals(paramString1, paramString2))
      return false;
    int i = this.tableDataNameList.indexOf(paramString1);
    if (i != -1)
      this.tableDataNameList.set(i, paramString2);
    else
      return false;
    return true;
  }

  public void removeTableData(String paramString)
  {
    if (paramString == null)
      return;
    int i = this.tableDataNameList.indexOf(paramString);
    if (i != -1)
    {
      this.tableDataNameList.remove(i);
      this.tableDataList.remove(i);
    }
  }

  public void clearAllTableData()
  {
    this.tableDataNameList.clear();
    this.tableDataList.clear();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if ("TableDataMap".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final AbstractWizardRpt this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
              this.this$0.clearAllTableData();
            if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("NameTableData")))
            {
              String str;
              Object localObject = null;
              if ((str = paramXMLableReader.getAttr("name")) != null)
                localObject = str;
              AbstractWizardRpt.2 local2 = new AbstractWizardRpt.2(this, null);
              paramXMLableReader.readXMLObject(local2);
              this.this$0.putTableData(localObject, (TableData)local2.getObject());
            }
          }
        });
      }
      else if ("ParameterAttributes".equals(str1))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("showParameterWindow")) != null)
          setShowParameterWindow(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("parameterWindowPosition")) != null)
          setParameterWindowPosition(Integer.parseInt(str2));
      }
    }
  }

  protected void addWCelllElementCondition(TemplateReport paramTemplateReport, WizardCellElement paramWizardCellElement)
  {
    if (paramWizardCellElement == null)
      return;
    Condition localCondition = paramWizardCellElement.getCondition();
    if (localCondition != null)
    {
      ArrayList localArrayList = new ArrayList();
      LiteConditionUtils.getAllParameters(localCondition, localArrayList);
      ReportParameterAttr localReportParameterAttr = (paramTemplateReport.getTemplateWorkBook() == null) ? null : paramTemplateReport.getTemplateWorkBook().getReportParameterAttr();
      if (localReportParameterAttr == null)
      {
        localReportParameterAttr = new ReportParameterAttr();
        paramTemplateReport.getTemplateWorkBook().setReportParameterAttr(localReportParameterAttr);
      }
      int i = 0;
      int j = localArrayList.size();
      while (i < j)
      {
        localReportParameterAttr.addParameter((Parameter)localArrayList.get(i));
        ++i;
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if ((this.tableDataNameList != null) && (this.tableDataNameList.size() > 0))
    {
      paramXMLPrintWriter.startTAG("TableDataMap");
      for (int i = 0; i < this.tableDataNameList.size(); ++i)
      {
        String str = (String)this.tableDataNameList.get(i);
        TableData localTableData = (TableData)this.tableDataList.get(i);
        paramXMLPrintWriter.startTAG("NameTableData").attr("name", str);
        if (localTableData != null)
          DataXMLUtils.writeXMLTableData(paramXMLPrintWriter, localTableData);
        paramXMLPrintWriter.end();
      }
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.startTAG("ParameterAttributes").attr("showParameterWindow", this.showParameterWindow).attr("parameterWindowPosition", this.parameterWindowPosition).end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}